package com.teamit.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.teamit.entity.Employee;
import com.teamit.entity.Project;
import com.teamit.service.DocumentService;
import com.teamit.util.web.ServletUtil;

public class NewDocumentServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		ServletUtil.forword(request, response,"new_document");
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		DocumentService ds = new DocumentService();
		Employee employee = (Employee)ServletUtil.getSession(request).getAttribute("curr_employee");
		Project project = (Project) ServletUtil.getSession(request).getAttribute("project");
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		//System.out.println(title);
		//System.out.println(content);
		if(title != null && content != null){
			ds.saveDocument(title, content,employee.getId(),project.getId());
			response.sendRedirect("document.jspx");
		}else{
			response.sendRedirect("new_document.jspx");
		}
		
		
	}

}
